/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.moedik.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Sammy
 */
public class ConfigModel extends Model {

    public ConfigModel() {
        super();
    }

    public String getCompanyName() {
        String result = null;
        Statement stmt = null;

        try {
            stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT * FROM `config` WHERE `config`.`key` = 'company_name'");

            while (rs.next()) {
                result = rs.getString("value");
            }
        } catch (SQLException ex) {
            Logger.getLogger(ConfigModel.class.getName()).log(Level.SEVERE, null, ex);
        }

        return result;
    }

    public void setCompanyName(String companyName) {
        PreparedStatement stmt = null;

        try {
            String query = "UPDATE `config` SET `config`.`value` = '" + companyName + "' WHERE `config`.`key` = 'company_name'";

            stmt = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
            stmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(ConfigModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
